<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
require_once("includes/plugins/webshop/model/FgcmsCountryBean.class.php");
require_once("includes/plugins/webshop/model/FgcmsCustomerBean.class.php");
require_once("includes/plugins/webshop/model/FgcmsProductBean.class.php");
require_once("includes/plugins/webshop/model/FgcmsCheckoutBean.class.php");
require_once("includes/plugins/webshop/model/FgcmsSettingsBean.class.php");
include_once("includes/plugins/webshop/controller/FgcmsProduct.class.php");
include_once("includes/plugins/webshop/controller/FgcmsCheckoutShipping.class.php");
include_once("includes/plugins/webshop/controller/FgcmsCheckoutPayment.class.php");
include_once("includes/plugins/webshop/controller/FgcmsCheckout.class.php");


class FgcmsWebshop {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		//contructor function
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	/* 
	 * Set default category 
	 */
	public function view_form() {
		$subtotal= FgcmsCheckout::view_basket();
		FgcmsProduct::view_product_right();
		
		if(isset($_GET['page']) && $_GET['page']!=""){
			$cutpath = split("[_]", $_GET['page'],2);
			if($cutpath[0]=='checkout' || $cutpath[1]=='myaccount'){
				if(!isset($_SESSION['cust_id']) && $cutpath[1] != "basket"){
					$cutpath[0] = "customer";
					$cutpath[1] = "login";
				}	
				if($cutpath[0]=='checkout' && $cutpath[1] != "finish" && (!isset($_SESSION['total']) || $_SESSION['total'] == 0)){
					$cutpath[0] = "checkout";
					$cutpath[1] = "basket";
				}	
			}	
			isset($cutpath[1]) ? $TplFolder = "/" : $TplFolder = "";
			$folder = $cutpath[0].$TplFolder;
			$file = $folder.$cutpath[1].".tpl";
			if($cutpath[0] == 'customer'){
				include_once("includes/plugins/webshop/controller/FgcmsCustomer.class.php");
				$object = new FgcmsCustomer($this->db, $this->smarty);
				$object->process();
			}else if($cutpath[0] == 'checkout'){
				$object = new FgcmsCheckout($this->db, $this->smarty);
				$object->process($cutpath[1],$subtotal);
			}else if($cutpath[0] == 'allspecials'){
				$object = new FgcmsProduct($this->db, $this->smarty);
				$object->process();
				$object->view_all_specials();
			}else if($cutpath[0] == 'allfeatured'){
				$object = new FgcmsProduct($this->db, $this->smarty);
				$object->process();
				$object->view_all_featured();
			}else if($cutpath[0] == 'product'){
				$object = new FgcmsProduct($this->db, $this->smarty);
				$object->process();
			}
			
			$tplname = FgcmsTemplateBean::get_active_template($this->db);
			if(file_exists("view/".$tplname->name."/".$file)){
				$page = $this->smarty->fetch($file);
						
				$this->smarty->assign('WSPAGE',$page);
			}
		}
		else if(isset($_GET['subcat']) || isset($_GET['cat']))
			FgcmsProduct::process();	
		
	}
}
?>
